#pragma once
#include "../Ode.h"

namespace Skill
{
	namespace Ode
	{
		public enum class DErrorType
		{
			///<summary>
			/// unknown error
			///</summary>
			Unknown = d_ERR_UNKNOWN,
			///<summary>
			/// internal assertion failed 
			///</summary>
			IAssert = d_ERR_IASSERT,
			///<summary>
			/// user assertion failed 
			///</summary>
			Assert = d_ERR_UASSERT,
			///<summary>
			/// user assertion failed 
			///</summary>
			Lcp = d_ERR_LCP
		};

		public delegate void DMessageFunction(int errNum, String^ msg, System::Object^ data);

		public ref class DError abstract sealed
		{
		public:

			static DError();

			static event DMessageFunction^ ErrorHandler;
			static event DMessageFunction^ DebugHandler;
			static event DMessageFunction^ MessageHandler;			

			/// <summary>
			/// generate a fatal error
			/// </summary>
			static void GenerateError (int errNum, String^ msg, System::Object^ data);
			/// <summary>
			/// generate a debug trap
			/// </summary>
			static void GenerateDebug (int errNum, String^ msg, System::Object^ data);
			/// <summary>
			/// generate a message
			/// </summary>
			static void GenerateMessage (int errNum, String^ msg, System::Object^ data);

		private:
			static Object^ _ErrorObj;
			static Object^ _DebugObj;
			static Object^ _MessageObj;
		internal:
			static void Raise_ErrorHandler(int errNum, String^ msg)
			{				
				ErrorHandler(errNum,msg,_ErrorObj);
				_ErrorObj = nullptr;
			}
			static void Raise_DebugHandler(int errNum, String^ msg)
			{				
				DebugHandler(errNum,msg,_DebugObj);
				_DebugObj = nullptr;
			}
			static void Raise_MessageHandler(int errNum, String^ msg)
			{				
				MessageHandler(errNum,msg,_MessageObj);
				_MessageObj = nullptr;
			}
		};
	}
}